/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Grid = require("grid");
	var aw = require("ajaxwrapper");
	 var incomefile = require("../store/incomefile");
	
    var instance = {
        initComponent: function (params, widget) {
        	var grid = new Grid({
        		 parentNode: ".J-grid",
         	     autoRender: false,
         	    model: {
        	        url: "api/roomstatistics/querybyroomtype",
        	        params: function() {
        	        	var subnav = widget.get("subnav");
        	        	var rangeDate = subnav.getValue("visitTime");
        	        	
        	            return {
        	            	"startDate":rangeDate.start,
        	            	"endDate":rangeDate.end,
        	            	fetchProperties:incomefile.fetchProperties
        	            };
        	        },
        	        columns:[{
        	        	 name: "checkinType",
        	             label: "入住类型"
        	        },{
        	        	 name: "count",
        	             label: "数量",
        	             format: "detail",
        	             formatparams: {
        	            	 key: "detail",
                     		 handler: function(index,data,rowEle){
                     			console.log(data);
                     			var subnav = widget.get("subnav");
                	        	var rangeDate = subnav.getValue("visitTime");
                     			 widget.hide([".J-grid"]).show([".J-detailgrid"]);
                     			 widget.get("subnav").show(["cancel"]).hide(["visitTime"]);
                     			 widget.get("detailgrid").refresh({
                     				 checkinType:data.checkinType,
                        	         "startDate":rangeDate.start,
                        	         "endDate":rangeDate.end,
                        	          fetchProperties:"employer,destination,memCount,checkinDate,checkoutDate,roomPay,foodPay,healthPay," +
                        	            	"waterPay,electricPay,trafficPay,pickupPay,otherPay,allPay"
                     			 },function(data2){
                     				var j = 0;
                     				for(var i in data2){
                     					j+=(data2[i].allPay == null ? 0 : data2[i].allPay);
                     				}
                     				var k = parseFloat(j).toFixed(2);
                     				widget.get("detailgrid").setTitle("收入总金额:" + k + "元");
                     			 });
                     		}	
        	             }
        	        },{
        	        	 name: "roomPay",
        	             label: "住宿费(元)",
        	             format:function(val){
 							return Number(val).toFixed(2);
 						}
        	        },{
        	        	 name: "foodPay",
        	             label: "餐饮费(元)",
        	             format:function(val){
 							return Number(val).toFixed(2);
 						}
        	        },{
        	        	 name: "healthPay",
        	             label: "康乐费(元)",
        	             format:function(val){
 							return Number(val).toFixed(2);
 						}
        	        },{
        	        	name: "waterPay",
        	            label: "水费(元)",
        	            format:function(val){
							return Number(val).toFixed(2);
						}
        	        },{
        	        	name: "electricPay",
       	                label: "电费(元)",
       	                format:function(val){
							return Number(val).toFixed(2);
						}
        	        },{
        	        	name: "trafficPay",
       	                label: "大交通往返费(元)",
       	                format:function(val){
							return Number(val).toFixed(2);
						}
        	        },{
        	        	name: "pickupPay",
       	                label: "接送往返费(元)",
       	                format:function(val){
							return Number(val).toFixed(2);
						}
        	        },{
        	        	name: "otherPay",
       	                label: "其他费用(元)",
       	                format:function(val){
							return Number(val).toFixed(2);
						}
        	        },{
        	        	name: "allPay",
       	                label: "收入总金额(元)",
       	                format:function(val,row){
       	                	console.log(row);
       	                	var val = 0;
       	                	val+=(row.roomPay+row.foodPay+row.healthPay+row.waterPay+row.electricPay+row.trafficPay+row.pickupPay+row.otherPay);
       	             	    row.allPay = val;
							return Number(val).toFixed(2);
       	                
						}
        	        }]
         	    }
        	});
        widget.set("grid",grid);
        }
    };
    module.exports = instance;
});
